﻿
using System.Collections.Generic;
namespace Jayden.Dll.Web.Events
{
	public class HttpCommandHandler : HttpEventHandler
	{
		private HashSet<string> m_Commands;

		public HttpCommandHandler(params string[] commands)
		{
			m_Commands = new HashSet<string>(commands);
		}

		protected virtual void ProcessCommand(HttpHandlerContext context, string command) { }

		protected override void ProcessRequest(HttpHandlerContext context)
		{
			string command = context.Context.Request["command"];
			if (m_Commands.Contains(command))
			{
				if (context.Json != null)
				{
					context.Json.Add("command", command);
#if DEBUG
					context.Json.Add("httpHandler", Id);
#endif
				}
				context.Logger.Fine("Executing command '{0}' of Handler '{1}'.", command, Id);
				ProcessCommand(context, command);
			}
		}
	}
}
